package ui_logic;

import game_logic.Controller;
import game_logic.GameFactory;
import game_logic.control.GameController;
import game_logic.control.MoveController;
import game_logic.model.Board;

import game_logic.Controller;
import game_logic.GameFactory;
import game_logic.control.ai.*;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class StartUI {
    private JPanel panel1;
    private JLabel gameMode;
    private JButton PvP;
    private JButton AI;
    private JButton match;
    private JButton playOneself;
    private JLabel startPicture;
    private JFrame frame;

    public StartUI() {
        PvP.setText("PvP已知(IP)");
    }
    public void initial(){
        frame = new JFrame("StartUI");
        frame.pack();
        //设置窗口大小
        frame.setSize(500, 620);
        frame.setContentPane(panel1);
        //设置按下右上角X号后关闭
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //窗口居中
        frame.setLocationRelativeTo(null);
        //窗口可见
        frame.setVisible(true);

        Icon icon = new ImageIcon("res/img/startPic.jpg");
        startPicture.setIcon(icon);
        playOneself.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Controller controllerR = GameFactory.makeGame("", true, true, null, 0);
                controllerR.gameStart();
            }
        });

        PvP.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setVisible(true);
                SwingUtilities.invokeLater(() -> {
                    LinkUI t = new LinkUI();
                    t.startLinking();
                    t.start();
                });
            }
        });
        match.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setVisible(true);
                SwingUtilities.invokeLater(() -> {
                    MatchUI t = new MatchUI();
                    t.startMatching();
                    t.start();
                });
            }

        });
        // 添加AI接口
        AI.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new game_logic.control.ai.Start().start();
            }
        });
    }

    public static void main(String[] args) {
        StartUI s = new StartUI();
        s.initial();
    }
}
